string author = "Live";
string pluginName = "ReplacAr15 替换AR15 插件";
string version = "1.0";

void OnPluginInit()
{

    PluginData::SetAuthor(author);
    PluginData::SetName(pluginName);
    PluginData::SetVersion(version);


    ThePresident.InfoFeed("插件:"+pluginName+"| 版本:"+version+"| 作者:"+author,false);

    Events::ThePresident::OnRandomItemSpawn.Hook( @OnRandomItemSpawn );

    Events::Player::OnPlayerConnected.Hook( @OnPlayerConnected );

    Events::Player::OnPlayerSpawn.Hook( @OnPlayerSpawn );

    MapReplacAr15();
}

HookReturnCode OnRandomItemSpawn(const string &in strClassname, CBaseEntity@ pEntity)
{
    if(Utils.StrContains("weapon_acr",strClassname)||Utils.StrContains("weapon_ak74",strClassname)||Utils.StrContains("weapon_scar",strClassname)){
        ReplacAr15(pEntity);
    }
    Chat.PrintToConsole(all,"检测到生成了"+strClassname+",已替换成AR15");
	return HOOK_CONTINUE;
}

void MapReplacAr15(){
    string name_ak74 = "weapon_ak74";
        CBaseEntity @base_ak74 = FindEntityByClassname( null, name_ak74 );
        while( base_ak74 !is null ){
            ReplacAr15(base_ak74);
            @base_ak74 = FindEntityByClassname( base_ak74, name_ak74 );
        }
        string name_sacr = "weapon_scar";
        CBaseEntity @base_scar = FindEntityByClassname( null, name_sacr );
        while( base_scar !is null ){
            ReplacAr15(base_scar);
            @base_scar = FindEntityByClassname( base_scar, name_sacr );
        }
        string name_acr = "weapon_acr";
        CBaseEntity @base_acr = FindEntityByClassname( null, name_acr );
        while( base_acr !is null ){
            ReplacAr15(base_acr);
            @base_acr = FindEntityByClassname( base_acr, name_acr );
        }
        Chat.PrintToConsole(all,"替换AR15完毕");
}

void ReplacAr15(CBaseEntity@ pEntity){
    Vector v = pEntity.GetAbsOrigin();
    QAngle qa = pEntity.GetAbsAngles();
    pEntity.SUB_Remove();
    EntityCreator::Create("weapon_ar15", v, qa);
}

HookReturnCode OnPlayerConnected(CTerrorPlayer@ pPlayer)
{
    MapReplacAr15();
    return HOOK_CONTINUE;
}

HookReturnCode OnPlayerSpawn(CTerrorPlayer@ pPlayer)
{
    MapReplacAr15();
    return HOOK_CONTINUE;
}

void ThePresident_OnMapStart(){
    MapReplacAr15();
}

void ThePresident_OnRoundStart(){
    MapReplacAr15();
}